package cn.smbms.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * @Classname User
 * @Description TODO
 * @Date 2020-10-10 10:25
 * @Created by 26440
 */
@Data
public class User {
    @TableId(type = IdType.AUTO)
    private Integer id;
    private String userCode;
    private String userName;
    private String userPassword;
    private Integer createdBy;
    private Date creationDate;
    private Integer modifyBy;
    private Date modifyDate;
    private Integer userRole;
    private String phone;
    private String address;
    private Integer gender;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday;

    @TableField(exist = false)
    private Integer age;//年龄
    @TableField(exist = false)
    private String userRoleName;    //用户角色名称

    public Integer getAge() {
		/*long time = System.currentTimeMillis()-birthday.getTime();
		Integer age = Long.valueOf(time/365/24/60/60/1000).IntegerValue();*/
        if(birthday == null){
            return 0;
        }
        Date date = new Date();
        Integer age = date.getYear()-birthday.getYear();
        return age;
    }
}
